package com.dhy.dbCore.dataSource;

import javax.sql.DataSource;
import java.io.PrintWriter;
import java.sql.*;
import java.util.logging.Logger;

/**
 * @author 大忽悠
 * @create 2022/6/6 21:20
 */
public class MyDataSource implements DataSource {
    private Connection connection;

    public MyDataSource(String url,String username,String pwd) {
        try {
            connection=DriverManager.getConnection(url,username,pwd);
        } catch (SQLException e) {
            throw new RuntimeException("获取数据库连接出错: ",e);
        }
    }

    public MyDataSource() {
        try {
            connection=DriverManager.getConnection(
                    "jdbc:mysql://110.40.155.17:3306/test?userSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8"
                    ,"root","126433");
        } catch (SQLException e) {
            throw new RuntimeException("获取数据库连接出错: ",e);
        }
    }


    @Override
    public Connection getConnection() throws SQLException {
        return connection;
    }


    @Override
    public Connection getConnection(String username, String password) throws SQLException {
        return connection;
    }


    @Override
    public <T> T unwrap(Class<T> iface) throws SQLException {
        return null;
    }

    @Override
    public boolean isWrapperFor(Class<?> iface) throws SQLException {
        return false;
    }


    @Override
    public PrintWriter getLogWriter() throws SQLException {
        return null;
    }


    @Override
    public void setLogWriter(PrintWriter out) throws SQLException {

    }


    @Override
    public void setLoginTimeout(int seconds) throws SQLException {

    }


    @Override
    public int getLoginTimeout() throws SQLException {
        return 0;
    }


    @Override
    public Logger getParentLogger() throws SQLFeatureNotSupportedException {
        return null;
    }
}
